// pages/Personal/Personal.js
//获取应用实例
var util = require('../../utils/util.js')
const app = getApp()

Page({
    data: {
        userInfo: {},
        hasUserInfo: false,
        canIUse: wx.canIUse('button.open-type.getUserInfo'),
        text: '获取验证码', //按钮文字
        getCodeDisabled: false, //按钮是否禁用
        countDown: 60,
        name:'郑自航',//null,
        phone: '18071859876', //获取到的手机栏中的值
        code: null,
        success: false,
        showModal: false //弹出框
    },
    // 控制弹出内容(测试用)
    showRegiSuccess: function() {
        this.setData({
            showModal: true
        })
    },
    //跳转到首页
    navigateToIndex(){
        this.setData({
            showModal: false
        })
        wx.navigateTo({
            url: '/pages/index/index',
        })
    },
    onNameInput(e) {
        this.setData({
            name: e.detail.value
        })
    },
    onPhoneInput(e) {
        this.setData({
            phone: e.detail.value
        })
    },
    onCodeInput: function(e) {
        console.log(e);
        this.setData({
            code: e.detail.value
        })
    },
    /*** 获取验证码*/
    doGetCode: function() {
        var that = this;
        let phone = that.data.phone;
        app.doGetCode(phone,that);
        return;
    },
    submit: function () {
        app.submitUserInfo(this);
    },
    //  用户头像信息函数
    onLoad: function() {
        if (app.globalData.userInfo) {
            this.setData({
                userInfo: app.globalData.userInfo,
                hasUserInfo: true
            })
        } else if (this.data.canIUse) {
            // 由于 getUserInfo 是网络请求，可能会在 Page.onLoad 之后才返回
            // 所以此处加入 callback 以防止这种情况
            app.userInfoReadyCallback = userInfo => {
                this.setData({
                    userInfo: userInfo,
                    hasUserInfo: true
                })
            }
        } else {
            // 在没有 open-type=getUserInfo 版本的兼容处理
            wx.getUserInfo({
                success: res => {
                    app.globalData.userInfo = res.userInfo
                    this.setData({
                        userInfo: res.userInfo,
                        hasUserInfo: true
                    })
                }
            })
        }
    },
    getUserInfo: function(e) {
        console.log(e)
        app.globalData.userInfo = e.detail.userInfo
        this.setData({
            userInfo: e.detail.userInfo,
            hasUserInfo: true
        })
    }
})